package com.zb.repository;

import com.zb.entity.Collection;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;


/**
 * Collection DAO层
 * @author HBY
 */
public interface CollectionRepository extends JpaRepository<Collection,Long> , JpaSpecificationExecutor<Collection> {

    /**
     * 根据用户id查找收藏夹
     * @param userId 用户ID
     * @return 收藏夹
     */
    Collection findByUser_Id(Long userId);

    /**
     * 根据商品id查找某商品被收藏的次数
     * @param itemId
     * @return
     */
    @Query(value = "SELECT COUNT(item_id) FROM sys_collection_item WHERE item_id = ?1", nativeQuery = true)
    Integer countByItemId(Long itemId);
}
